package com.monscape.tag_c;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

import com.monscape.tag_c.supportclasses.AppManager;
import com.monscape.tag_c.supportclasses.SoundManager;

public class RootActivity extends Activity {

	private final int SOUND_BGM = 0;
	private final int SOUND_BUTTON1 = 1;
	private final int SOUND_BUTTON2 = 2;

	private SoundManager _soundManager = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_root);

		this.initSounds(); // Initialize SoundManager

		Thread jsonThread = new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				String strURL = "http://map.daum.net/route/route.json?callback=jQuery18105068596978671849_1358838674186&carMode=SHORTEST_REALTIME&carOption=NONE&walkMode=RECOMMENDATION&walkOption=NONE&sName=Start&sX=438300.000000&sY=1107910.000000&eName=Dest&eX=424551.000000&eY=1103692.000000";
				try {
					URL url = new URL(strURL);
					InputStream input = null;
					try {
						input = url.openStream();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					Log.e("URL", input.toString());
				} catch (MalformedURLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		
		jsonThread.start();
		
		// String json = "{" + "  \"query\": \"Pizza\", "
		// + "  \"locations\": [ 94043, 90210 ] " + "}";
		//
		// try {
		// JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
		// String query = object.getString("query");
		// JSONArray locations = object.getJSONArray("locations");
		//
		// Log.e("Query", query);
		// Log.e("Locations", String.valueOf(locations.getInt(0)));
		// } catch (JSONException e) {
		// Log.d("Test", e.getMessage());
		// }

		// CustomIndicator.showIndicatorView(); // Show Indicator
		// CustomIndicator.hideIndicatorView(); // Hide Indicator

		/*
		 * 앱 정보 저장을 위한 SharedPreferences 데이터 저장 & 삭제 과정
		 * 
		 * SharedPreferences sp = getSharedPreferences("setting", MODE_PRIVATE);
		 * Editor edit = sp.edit();
		 * 
		 * edit.putString("emgNumber", "112"); // 저장 edit.putString("house",
		 * "부평2동"); edit.putString("job", "인천대학교");
		 * 
		 * edit.remove("job"); // 삭제
		 * 
		 * edit.commit();
		 */

		/*
		 * 앱 정보 저장을 위한 SharedPreferences 데이터 읽어오기
		 * 
		 * SharedPreferences sp = getSharedPreferences("setting", MODE_PRIVATE);
		 * String number = sp.getString("emgNumber", "");
		 */
	}

	private void initSounds() {
		// _soundManager = new SoundManager();
		// _soundManager.initSounds(this);
		// _soundManager.addSound(SOUND_BGM, R.id.filename);
		// _soundManager.addSound(SOUND_BUTTON1, R.id.filename);
		// _soundManager.addSound(SOUND_BUTTON2, R.id.filename);
		// _soundManager.playLoopedSound(SOUND_BGM);
		// _soundManager.playSound(SOUND_BUTTON1);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_root, menu);
		return true;
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		AppManager.getInstance().set_currentActivity(this);
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}
}
